#pragma once
#include<assert.h>
namespace xtb
{
	template<class T>
	struct ListNode
	{
		ListNode<T>* _prev;
		ListNode<T>* _next;
		T _Date;
		ListNode<T>(const T& x=T())
			:_prev(nullptr)
			,_next(nullptr)
			,_Date(x)
		{

		}
	};
	template<class T>
	struct List_iterator
	{
		typedef ListNode<T> Node;
		typedef List_iterator self;
		Node* _node;
		List_iterator(Node* it)
		{
			_node = it;
		}
		self& operator++()
		{
			_node = _node->_next;
			return *this;
		}
		self operator++(int)
		{
			Node temp(_node);
			temp = temp->_next;
			return temp;
		}
		self& operator--()
		{
			_node = _node->_prev;
			return *this;
		}

		self operator--(int)
		{
			Node temp(_node);
			temp = temp->_prev;
			return temp;
		}
		T& operator*()
		{
			return _node->_Date;
		}
		bool operator!=(const self& s)
		{
			return _node != s._node;
		}
		bool operator==(const self& s)
		{
			return _node == s._node;
		}
	};
		template<class T>
		class list
		{
		public:
			typedef List_iterator<T> iterator;
			typedef ListNode<T> Node;
			void empty_init()
			{
				head = new Node;
				head->_next = head;
				head->_prev = head;
			}
			list()
			{
				empty_init();
			}
			iterator begin()
			{
				return head->_next;
			}
			iterator end()
			{
				return head;
			}
			void clear()
			{	
				iterator it = begin();
				while (it != end())
				{
					it = erase(it);
				}
			}
			~list()
			{
				clear();
				delete head;
			}
			list(list<T>& lt)
			{

			}
			void swap(list<T>& tmp)
			{

			}
			list<T>& operator=(list<T> lt)
			{

			}
			void push_back(const T& x)
			{
				Node* newnode = new Node(x);
				Node* tail = head->_prev;
				tail->_next = newnode;
				newnode->_prev = tail;
				newnode->_next = head;
				head->_prev = newnode;
			}
			void push_front(const T& x)
			{


			}
			void pop_back()
			{
				Node* pos = head->_prev;
				Node* prev = pos->_prev;
				prev->_next = head;
				head->_prev = prev;

			}
			void pop_front()
			{

			}
			iterator insert(iterator pos, const T& x)
			{

			}
			iterator erase(iterator pos)
			{
				assert(pos != end());

				Node* cur = pos._node;
				Node* prev = cur->_prev;
				Node* next = cur->_next;
				prev->_next = next;
				next->_prev = prev;

				delete cur;

				return next;
			}

		private:
			Node* head;
		};
		void test_list1()
		{
			list<int> lt;
			lt.push_back(1);
			lt.push_back(2);
			lt.push_back(3);
			lt.push_back(4);

			list<int>::iterator it = lt.begin();
			while (it != lt.end())
			{
				//*it += 10;

				cout << *it << " ";
				++it;
			}
			cout << endl;

			for (auto e : lt)
			{
				cout << e << " ";
			}
			cout << endl;
		}
}
